package com.test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class test3 {
    public static void main(String[] args) {
        String str = "student. a am I";
        System.out.println(ReverseSentence(str));
    }

    //反转单词顺序，例如student. a am I ，原顺序是I am a student.
    public static String ReverseSentence(String str){
        if (str.trim().length() == 0)
            return str;
        String[] strs = str.split(" ");
        StringBuffer buffer = new StringBuffer();
        for(int i =strs.length-1; i >= 0;i--){
            buffer.append(strs[i]);
            if(i > 0){
                buffer.append(" ");
            }
        }
        return buffer.toString();
    }
}
